//
//  SinaVisitorViewController.swift
//  SinaWeiBo
//
//  Created by 王忠楠 on 16/9/20.
//  Copyright © 2016年 wangzn. All rights reserved.
//

import UIKit

class SinaVisitorViewController: UITableViewController,SinaVisitorViewDelegate {

    

       //用户登录标记
    var isLogin: Bool = SinaUserAccountViewModel.sharedUserAccountViewModel.isLogin
    
    //访客试图
    var visitorView : SinaVisitorView?
    
        //自定义view视图
        override func loadView(){
            
            if isLogin {
                super.loadView()
            }else{
                //自己提供一个视图
                 visitorView = SinaVisitorView()
               //设置代理
                visitorView?.delegate = self
                //设置闭包
                visitorView?.loginClosure = {  [weak self] in
                    print("我是访客试图闭包调用过来的")
                    self?.requestLoginOperation()
                
                }
                    view = visitorView
                
                setupNavUI()
            }
       
            
        }
        
    
        
        
    
     override func viewDidLoad() {
           super.viewDidLoad()
}
   //设置导航栏按钮
    private func setupNavUI() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(loginAction))
        
        
    }
    
    //点击事件
    @objc private func loginAction(){
        
        print("你点击了登录操作")
        requestLoginOperation()
        
    }

    //实现代理方法
    func didSelectedLogin() {
        print("我是访客试图代理对象调用过来的")
    }
    
    
    
    //请求登录操作
    
    private func requestLoginOperation(){
        
        let oAuthVC = SinaOAuthViewController()
        
        let nav = SinaNavigationViewController(rootViewController:oAuthVC)
        
        present(nav,animated: true,completion: nil)
        
    }
    
    
    
    
    
    
    
    
}
